//
//  HomeViewController.m
//  grainHouse
//
//  Created by 北风 on 14-10-13.
//  Copyright (c) 2014年 北风. All rights reserved.
//

#import "HomeViewController.h"
#import "LeftViewController.h"
#import "FRDLivelyButton.h"
#import "HomeTableViewCell.h"
#import "ScrollViewTableViewCell.h"
#import "Custom6TableViewCell.h"
#import "ThirdBigTableViewCell.h"
#import "Connect.h"
#import "Photos.h"
#import "WangLuo.h"
#import "UIImageView+WebCache.h"
#import "HCViewController.h"
#import "MJRefresh.h"
#import "SpaceModel.h"
#import "GDataXMLNode.h"
#import "StyleModel.h"
#import "ColorModel.h"
#import "ColorTableViewCell.h"
@interface HomeViewController ()<CommentViewControllerDelegate>
{
    int rowIndex;
}

@property(nonatomic ,retain)FRDLivelyButton *burgeButton;
@property (assign,nonatomic)NSInteger current ;


@end

@implementation HomeViewController
{
    kFRDLivelyButtonStyle newStyle;
}
- (void)dealloc
{
    [_Customtable release];
    [_buyTable release];
    [super dealloc];
}
- (void)pushViewController:(UIViewController *)viewController
{
    NSLog(@"push");
    [self.navigationController pushViewController:viewController animated:YES];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
         _photo = [[Photos alloc] init];
        self.modelArray = [NSMutableArray array];
        self.DanPinArray = [NSMutableArray array];
        self.xmlArray = [NSMutableArray array];
        self.stalyArray = [NSMutableArray array];
        self.colorArray = [NSMutableArray array];
        self.imageName = [NSMutableArray array];
        
    }
    return self;
}

- (void)viewDidLoad
{

    [super viewDidLoad];
    self.title = @"主页";

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"菜单"
                                                                             style:UIBarButtonItemStylePlain
                                                                            target:(LeftViewController *)self.navigationController
                                                                            action:@selector(showMenu)];
    
 
   
    [self creatTableView];
    [self setupRefresh];
    [self jieXi];
    [self DanPinShuJu];
    [self creatXML]; //解析XML
    [self styleXMl];
    [self colorXMl];
    
    rowIndex = -1;
}




#pragma mark - 侧边栏效果
- (void)buttonAction:(FRDLivelyButton *)sender
{
    newStyle = (newStyle + 1) % 2;
    [sender setStyle:newStyle animated:YES];
    [(LeftViewController *)self.navigationController showMenu];
    
}


#pragma mark -
#pragma mark - XML解析筛选数据
-(void)creatXML{
    
    NSString * path = [[NSBundle mainBundle]pathForResource:@"spacesMenu" ofType:@"xml"];
    NSData * data = [NSData dataWithContentsOfFile:path];
    GDataXMLDocument * doc = [[GDataXMLDocument alloc] initWithData:data options:0 error:nil];
    GDataXMLElement * root = [doc rootElement];
    
    NSArray * arr = [root elementsForName:@"item"];
    for (GDataXMLElement * element in arr) {
        SpaceModel * model = [SpaceModel spaceModelWithUid:[[element attributeForName:@"id"] stringValue] categoryId:[[element attributeForName:@"categoryId"] stringValue] cnCatName:[[element attributeForName:@"cnCatName"] stringValue] enCatName:[[element attributeForName:@"enCatName"] stringValue] pid:[[element attributeForName:@"pid"] stringValue]];
        
        [self.xmlArray addObject:model];
        
    }
    
}


-(void)styleXMl{
    
    NSString * path = [[NSBundle mainBundle]pathForResource:@"projectStylesMenu" ofType:@"xml"];
    NSData * data = [NSData dataWithContentsOfFile:path];
    GDataXMLDocument * doc = [[GDataXMLDocument alloc] initWithData:data options:0 error:nil];
    GDataXMLElement * root = [doc rootElement];
    
    NSArray * arr = [root elementsForName:@"item"];
    for (GDataXMLElement * element in arr) {
         StyleModel * model = [StyleModel spaceModelWithUid:[[element attributeForName:@"id"] stringValue] categoryId:[[element attributeForName:@"categoryId"] stringValue] cnCatName:[[element attributeForName:@"cnCatName"] stringValue] enCatName:[[element attributeForName:@"enCatName"] stringValue] pid:[[element attributeForName:@"pid"] stringValue]];
        
        [self.stalyArray addObject:model];
        
    }
    
}


-(void)colorXMl{
    
    NSString * path = [[NSBundle mainBundle]pathForResource:@"photosNewMenu" ofType:@"xml"];
    NSData * data = [NSData dataWithContentsOfFile:path];
    GDataXMLDocument * doc = [[GDataXMLDocument alloc] initWithData:data options:0 error:nil];
    GDataXMLElement * root = [doc rootElement];
    
    NSArray * arr = [root elementsForName:@"item"];
    for (GDataXMLElement * element in arr) {
         ColorModel * model = [ColorModel spaceModelWithUid:[[element attributeForName:@"id"] stringValue] categoryId:[[element attributeForName:@"categoryId"] stringValue] cnCatName:[[element attributeForName:@"cnCatName"] stringValue] enCatName:[[element attributeForName:@"enCatName"] stringValue] pid:[[element attributeForName:@"pid"] stringValue]];
        
        [self.colorArray addObject:model];
        
    }
    NSLog(@"%@",self.colorArray);

    
}





#pragma mark - 商品数据解析
-(void)jieXi{
    
    
    //http://api.guju.com.cn/v2/photo/flownew?start=0&count=10&user=(null)&cate=0&style=0&color=0
    
    Connect *jiexi = [[Connect alloc] init];
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"0",@"start",@"10",@"count",@"(null)",@"user",@"0",@"cate",@"0",@"style",@"0",@"color" ,nil];
    [dic setValue:[NSString stringWithFormat:@"%d",_page1 + 10] forKey:@"start"];
    //[dic setValue:@"style" forKey:[NSString stringWithFormat:@"%@",self.styleId]];
    [jiexi connectWithUrl:@"http://api.guju.com.cn/v2/photo/flownew?" pramter:dic passValue:^(id result) {
    
        NSArray *array = [result objectForKey:@"photos"];
        
        for (NSDictionary *dic  in array) {

        _photo = [[Photos alloc] init];
        [_photo setValuesForKeysWithDictionary:dic];
        [_modelArray addObject:_photo];
            
    }
     
        [_buyTable reloadData];
        
    }];
    
}

#pragma mark - 单品数据解析
-(void)DanPinShuJu{
    
  //http://api.guju.com.cn/v2/product/productFlowNew?start=0&count=10&user=(null)&cate=0&style=0&color=0
    
    Connect *danPin = [[Connect alloc] init];
    
    [danPin connectWithUrl:[NSString stringWithFormat:@"http://api.guju.com.cn/v2/product/productFlowNew?start=%d&count=10&user=(null)&cate=0&style=0&color=0",self.page2 + 10]pramter:nil passValue:^(id result) {
        NSLog(@"%@",result);
            
        NSMutableArray *aray  = [result objectForKey:@"products"];
        for (NSDictionary *dictionary in aray) {
                
        DanPin *only = [[DanPin alloc] init];
        [only setValuesForKeysWithDictionary:dictionary];
            
            [_DanPinArray addObject:only];
            
        }
        
        
        [_Customtable reloadData];

    }];
    
    
    
    
}


#pragma mark - 创建TableView
-(void)creatTableView{
    
    self.navigationController.navigationBar.translucent = NO;
    UIColor *color = [UIColor orangeColor];
    UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:@"筛选" style:UIBarButtonItemStyleBordered target:self action:@selector(barButtonAction:)];
    barButton.tintColor = [UIColor magentaColor];
    self.navigationItem.rightBarButtonItem = barButton;
    
    NSDictionary *dic = [NSDictionary dictionaryWithObject:color forKey:UITextAttributeTextColor];
    
    self.navigationController.navigationBar.titleTextAttributes = dic;
    
    
    _bigScr = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, 320, 600)];
    [_bigScr setContentSize:CGSizeMake(320 * 2, 0)];
    _bigScr.delegate = self;
    _bigScr.pagingEnabled = YES;
    [self.view addSubview:_bigScr];
    
    //搭配
    _buyTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, 320, 500) style:UITableViewStyleGrouped];
    _buyTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    _buyTable.delegate = self;
    _buyTable.dataSource = self;
    [self.bigScr addSubview:_buyTable];
    
    //商品
    _Customtable = [[UITableView alloc] initWithFrame:CGRectMake(320, 20, 320, 480)];
    _Customtable.dataSource = self;
    _Customtable.delegate = self;
    _Customtable.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.bigScr addSubview:_Customtable];
    
    
    //单品 搭配页
    NSArray *array = @[@"搭配",@"商品"];
    self.seg = [[UISegmentedControl alloc] initWithItems:array];
    self.seg.frame = CGRectMake(60, 0, 200, 30);
    self.seg.selectedSegmentIndex = 0;
    self.seg.tintColor = [UIColor orangeColor];
    [self.seg addTarget:self action:@selector(CreatSegment:) forControlEvents:UIControlEventValueChanged];
    self.seg.layer.cornerRadius = 3;
    self.seg.layer.masksToBounds = YES;
    [self.view addSubview:_seg];
    [_seg release];
    
    [self CreatTableView];
    
}


#pragma mark - 创建筛选页
-(void)CreatTableView{
    
    //创建底层的scrollview
    _shaiScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, -564, 320, 564)];
    _shaiScroll.contentSize = CGSizeMake(960, 0);
    _shaiScroll.backgroundColor = [UIColor whiteColor];
    _shaiScroll.pagingEnabled = YES;
    _shaiScroll.delegate = self;
    [self.view addSubview:_shaiScroll];
    
    //创建筛选tableView1
    _shaiTable = [[UITableView alloc] initWithFrame:CGRectMake(640, 30, 320, 564 - 64)];
    _shaiTable.dataSource = self;
    _shaiTable.delegate = self;
   
    [_shaiScroll addSubview:_shaiTable];
    
    //创建筛选tableView2
    _space = [[UITableView alloc] initWithFrame:CGRectMake(0, 30, 320, 600)];
    _space.dataSource = self;
    _space.delegate = self;
    [_shaiScroll addSubview:_space];
    
    //创建tableView3
    _manner = [[UITableView alloc] initWithFrame:CGRectMake(320, 30, 320, 600)];
    _manner.dataSource = self;
    _manner.delegate = self;
    [_shaiScroll addSubview:_manner];
    
    
    //创建segment
    NSArray *arr = @[@"全部空间", @"全部风格", @"全部颜色"];
     self.segment = [[UISegmentedControl alloc]initWithItems:arr];
     self.segment.frame = CGRectMake(30, _shaiScroll.frame.origin.y, 260, 30);
    _segment.selectedSegmentIndex = 0;
    _segment.tintColor = [UIColor orangeColor];
    [_segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    [_shaiTable addSubview:_segment];
    [self.view addSubview:_segment];
  
}



-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    _seg.selectedSegmentIndex = _bigScr.contentOffset.x / 320;
    _segment.selectedSegmentIndex = _shaiScroll.contentOffset.x / 320;
    
}


#pragma mark —segment
-(void)CreatSegment:(UISegmentedControl *)sender{
    NSInteger index = sender.selectedSegmentIndex;
    switch (index) {
        case 0:
            self.bigScr.contentOffset = CGPointMake(0, 0);
            break;
         
            case 1:
            self.bigScr.contentOffset = CGPointMake(320, 0);
        default:
            break;
            
    }
    
    
}

- (void)segmentAction:(UISegmentedControl *)sender
{
    NSInteger index = sender.selectedSegmentIndex;
    switch (index) {
        case 0:
            self.shaiScroll.contentOffset = CGPointMake(0, 0);
            break;
            
        case 1:
            self.shaiScroll.contentOffset = CGPointMake(320, 0);
            break;
        
        case 2:
            self.shaiScroll.contentOffset = CGPointMake(640, 0);
            default:
            break;
            
    }
    
}



#pragma mark - 筛选
-(void)barButtonAction:(UIBarButtonItem *)bar{
    
    if (bar.tintColor == [UIColor magentaColor]) {
        
    [UIView animateWithDuration:0.7 animations:^{
                bar.title = @"确定";
    [_shaiScroll setFrame:CGRectMake(0, 0, 320, 480)];
    bar.tintColor = [UIColor lightGrayColor];
 self.segment.frame = CGRectMake(30, _shaiScroll.frame.origin.y, 260, 30);
        
    }];
        
    }else{
        
        [UIView animateWithDuration:0.7 animations:^{

            bar.tintColor = [UIColor magentaColor];
            [_shaiScroll setFrame:CGRectMake(0, -500, 320, 480)];
   self.segment.frame = CGRectMake(30, _shaiScroll.frame.origin.y, 260, 30);
            bar.title = @"筛选";
            [_manner reloadData];
            [_shaiTable reloadData];
            [_space reloadData];
        }];
        
    }
    
    
}




#pragma mark - 返回cell的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (tableView == _buyTable) {
        
        if (indexPath.section == 0) {
            
            return 130;
            
        }
        if (indexPath.section == 1) {
            
            return 225;
        }
        
        if (indexPath.section == 2) {
            
            
            return 210;
            
        }
        
        return 220;
        
    }
    if (tableView == _space) {
        
        
        return 45;
        
    }
    if (tableView == _manner) {
        
        
        return 45;
    }
    if (tableView == _shaiTable) {
        
        
        return 50;
    }
    return 180;
}


#pragma mark - 返回多少行
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (tableView == _buyTable) {
        if (section == 0) {
        if (_modelArray.count == 0) {
                return 0;
        }
            return 1;
        }
        if (section == 1) {
            
            return 1;
        }
        if (section == 2) {
            
            return _modelArray.count - 5;
        }
        
    }
    
    if (tableView == _space) {
        
        return _xmlArray.count;
        
    }
    if (tableView == _manner) {
        
        return _stalyArray.count;
        
    }
    if (tableView == _shaiTable) {
        
        return _colorArray.count;
    }
    if (_DanPinArray.count == 0) {
        
        
        return 0;
    }
    
    return _DanPinArray.count;
    
}



#pragma mark - 创建TableViewCell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //
    if (tableView == _Customtable) {
        
        static NSString *string = @"sdlfkj";
        HomeTableViewCell *cell  = [tableView dequeueReusableCellWithIdentifier:string];
        if (!cell) {
            
            cell = [[[HomeTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:string]autorelease];
            
        }
        
        DanPin *dan = [_DanPinArray objectAtIndex:indexPath.row];
        NSURL *url = [NSURL URLWithString:dan.images[0]];
        [cell.PictureView sd_setImageWithURL:url];
        for (NSDictionary *dic in dan.addresses) {
            
            NSString *stri = [dic objectForKey:@"title"];
            
            [cell.jieLabel setText:stri];
            cell.piceLabel.text = [NSString stringWithFormat:@"%@￥",[dic objectForKey:@"price"]];
        }
        [cell.Xin.button setBackgroundImage:[UIImage imageNamed:@"iconfont-pinglun.png"] forState:UIControlStateNormal];
        cell.Xin.number.font = [UIFont systemFontOfSize:13];
        [cell.Xin.button addTarget:self action:@selector(heartAction:) forControlEvents:UIControlEventTouchDown];
        
        return cell;
        
    }
    if (tableView == _buyTable) {
        
        if (indexPath.section == 0) {
            
            static NSString *str = @"sdfk";
            ScrollViewTableViewCell *cell  = [tableView dequeueReusableCellWithIdentifier:str];
            if (!cell) {
                
                cell = [[[ScrollViewTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:str] autorelease];
                
            }
            Photos *phtot = [_modelArray objectAtIndex:indexPath.row];
            NSString *string = [NSString stringWithFormat:@"http://gooju.cn/dimages/%@_0_w640_h0_m0.jpg",phtot.uid];
            NSURL *url = [NSURL URLWithString:string];
            
            Photos *phtot1 = [_modelArray objectAtIndex:indexPath.row + 3];
            NSString *string1 = [NSString stringWithFormat:@"http://gooju.cn/dimages/%@_0_w640_h0_m0.jpg",phtot1.uid];
            NSURL *url1 = [NSURL URLWithString:string1];
            
            Photos *phtot3 = [_modelArray objectAtIndex:indexPath.row + 4];
            NSString *string3 = [NSString stringWithFormat:@"http://gooju.cn/dimages/%@_0_w640_h0_m0.jpg",phtot3.uid];
            NSURL *url3 = [NSURL URLWithString:string3];
            
            
            Photos *phtot4 = [_modelArray objectAtIndex:indexPath.row + 2];
            NSString *string4 = [NSString stringWithFormat:@"http://gooju.cn/dimages/%@_0_w640_h0_m0.jpg",phtot4.uid];
            NSURL *url4 = [NSURL URLWithString:string4];
            
            
            
            [cell.imageView1 sd_setImageWithURL:url];
            [cell.imageView2 sd_setImageWithURL:url1];
            [cell.imageView3 sd_setImageWithURL:url3];
            [cell.imageView4 sd_setImageWithURL:url4];
            return cell;
            
        }
        
        if (indexPath.section == 1) {
            
            
            NSString *string = @"dfser";
            Custom6TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:string];
            if (!cell) {
                
                cell = [[[Custom6TableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:string]autorelease];
                cell.delegate = self;
            }
            
            
            
            return cell;
            
        }
        
    }
//    //空间
    if (tableView == _space) {
        
      static NSString *space = @"sdlfkjasl";
        _cell = [tableView dequeueReusableCellWithIdentifier:space];
        if (!_cell) {
            
            _cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:space]autorelease];

            
        }
        
        if (indexPath.row == rowIndex) {
            
            _cell.accessoryType = UITableViewCellAccessoryCheckmark;
            _cell.textLabel.textColor = [UIColor orangeColor];
            
        }else{
            _cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            _cell.textLabel.textColor = [UIColor blackColor];
        }
        
        SpaceModel *model = [self.xmlArray objectAtIndex:indexPath.row];
        _cell.textLabel.text = model.cnCatName;

        _cell.textLabel.highlightedTextColor = [UIColor orangeColor];
   
        UIImageView *imageTag = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"photo_gou.png"]]autorelease];

        imageTag.contentMode = UIViewContentModeRight;
  

        return _cell;
        
    }
    //风格
    if (tableView == _manner) {
        
        static NSString *space = @"sdlkl";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:space];
        if (!cell) {
            
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:space]autorelease];
            
        }
         StyleModel *model = [self.stalyArray objectAtIndex:indexPath.row];
        cell.textLabel.text = model.cnCatName;
        cell.textLabel.highlightedTextColor = [UIColor orangeColor];
        return cell;
        
        
    }
    //颜色
    if (tableView == _shaiTable) {
        
        static NSString *space = @"fkjasl";
        ColorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:space];
        if (!cell) {
            
            cell = [[[ColorTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:space]autorelease];
            
        }
        
        ColorModel *model = [self.colorArray objectAtIndex:indexPath.row];
        cell.colorLabel.text = model.cnCatName;
        cell.colorLabel.highlightedTextColor = [UIColor orangeColor];
        if (indexPath.row > 0) {
            
            for (int i = 0; i < 10;i++ ) {
                
                NSString *string = [NSString stringWithFormat:@"%d.png",i + 10];
                
                
                [self.imageName addObject:string];
            }
            [cell.ColorView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",[self.imageName objectAtIndex:indexPath.row - 1]]]];
        }
        NSLog(@"%@",self.imageName);
        

        return cell;
//
    }
    
   static  NSString *strinb = @"dfsu";
    ThirdBigTableViewCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:strinb];
    if (!cell) {
        
        cell = [[[ThirdBigTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:strinb]autorelease];
        
    }
    
    Photos *phtot1 = [_modelArray objectAtIndex:indexPath.row + 5];
    NSString *string1 = [NSString stringWithFormat:@"http://gooju.cn/dimages/%@_0_w640_h0_m0.jpg",phtot1.uid];
    NSURL *url = [NSURL URLWithString:string1];
    [cell.BigImage sd_setImageWithURL:url];
    [cell.bigLabel setText:phtot1.title];
    cell.bigLabel.backgroundColor = [self TextColor];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    return cell;
}



#pragma mark - 单品页❤️点击方法
-(void)heartAction:(UIButton *)button{
  
    
    
    
    
    
}




#pragma mark - 创建section
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableVie{
    
    if (tableVie == _buyTable) {
        
        return 3;
        
    }
    
    return 1;
    
}


#pragma mark - 设置header
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (section == 1) {
        
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 10)];
        [self.view addSubview:view];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(view.bounds.origin.x + 10, view.bounds.origin.y -7, view.bounds.size.width, view.bounds.size.height)];
        label.textColor = [self orgeColor];
        label.text = @"设计师专栏";
        [view addSubview:label];
        return view;
    }
    if (section == 2) {
        
        
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 10)];
        [self.view addSubview:view];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(view.bounds.origin.x + 10, view.bounds.origin.y - 7, view.bounds.size.width, view.bounds.size.height)];
        label.textColor = [self orgeColor];
        label.text = @"搭配专栏";
        [view addSubview:label];
        return view;
        
        
    }
    
    return nil;
}


#pragma mark - 封装个颜色
-(UIColor *)orgeColor{
    
    
    UIColor  *color = [UIColor colorWithRed:100/255 green:100/255 blue:190/255 alpha:0.7];
    return color;
    
    
}



#pragma mark - 返回section高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    if (section == 0) {
//
        return 0.01;
    }

    return 10;
}


#pragma mark- 自定义透明色
-(UIColor *)TextColor{
    
    
    UIColor *color = [UIColor colorWithWhite:2 alpha:0.5];
    return color;
    
}


#pragma mark - tableViewCell点击方法



-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    _current = indexPath.row;
    
    NSIndexPath * lastIndexPath = [NSIndexPath indexPathForRow:rowIndex inSection:indexPath.section];
    UITableViewCell * lastCell = [_space cellForRowAtIndexPath:lastIndexPath];
    lastCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    UITableViewCell *cell = [_space cellForRowAtIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    rowIndex = indexPath.row;
    
//    [self.space reloadData];
    
//    HCViewController *hvc = [[HCViewController alloc] init];
//    [self.navigationController pushViewController:hvc animated:YES];
//    [hvc release];
 
    
    if (tableView == _manner) {
      
//    StyleModel *model = [_stalyArray objectAtIndex:indexPath.row];
//    self.styleId = model.categoryId;
        
    }
    if (tableView == _shaiTable) {
        
        
        
        
    }
    
    
    
    
}


#pragma mark -
#pragma mark 刷新
- (void)setupRefresh
{
    // 1.下拉刷新(进入刷新状态就会调用self的headerRereshing)
    [self.buyTable addHeaderWithTarget:self action:@selector(headerRereshing)];
//        [self.buyTable headerBeginRefreshing];
    
    [self.Customtable addHeaderWithTarget:self action:@selector(headerRereshing)];
//        [self.Customtable headerBeginRefreshing];
    
    // 2.上拉加载更多(进入刷新状态就会调用self的footerRereshing)
    [self.buyTable addFooterWithTarget:self action:@selector(footerRereshing)];
    //    [self.collectView footerEndRefreshing];
    
    [self.Customtable addFooterWithTarget:self action:@selector(footerRereshing)];
    //    [self.tableView footerEndRefreshing];
    
    // 设置文字(也可以不设置,默认的文字在MJRefreshConst中修改)
    self.buyTable.headerPullToRefreshText = @"下拉可以刷新了";
    self.buyTable.headerReleaseToRefreshText = @"松开马上刷新了";
    self.buyTable.headerRefreshingText = @"正在刷新中";
    
    self.buyTable.footerPullToRefreshText = @"上拉可以加载更多数据了";
    self.buyTable.footerReleaseToRefreshText = @"松开马上加载更多数据了";
    self.buyTable.footerRefreshingText = @"加载中";
    
    self.Customtable.headerPullToRefreshText = @"下拉可以刷新了";
    self.Customtable.headerReleaseToRefreshText = @"松开马上刷新了";
    self.Customtable.headerRefreshingText = @"正在刷新中";
    
    self.Customtable.footerPullToRefreshText = @"上拉可以加载更多数据了";
    self.Customtable.footerReleaseToRefreshText = @"松开马上加载更多数据了";
    self.Customtable.footerRefreshingText = @"加载中";
}

#pragma mark 开始进入刷新状态
- (void)headerRereshing
{

   
    //[self.DanPinArray removeAllObjects];
    //[self.modelArray removeAllObjects];
    // 2.2秒后刷新表格UI
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 刷新表格
         NSLog(@"刷新");
        [_buyTable reloadData];
        [_Customtable reloadData];
        // (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态
        [self.Customtable  headerEndRefreshing];
        [self.buyTable headerEndRefreshing];
    });
}

- (void)footerRereshing
{
    
    // 2.2秒后刷新表格UI
    self.page1 += 10;
    [self jieXi];
    self.page2 += 10;
    [self DanPinShuJu];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 刷新表格
        [self.buyTable reloadData];
        [self.Customtable reloadData];
        // (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态
        [self.buyTable footerEndRefreshing];
        [self.Customtable footerEndRefreshing];
    });
    
    
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
